<?php

require_once WP_PLUGIN_DIR . '/diapucp-events/defines.php' ;

class dia_pucp_events_showroom {
    //creates all the options to show the events' information

    public function dia_pucp_events_showroom(){
        add_filter( 'the_content', array( &$this, 'editor_content' ) );
    }

    function editor_content( $old_content ) {
            global $post;
            if ( 'true' == get_post_meta( $post->ID, DPEM_FIELD_IS_EVENT, true ) ){
                $metadata = array();
                $metadata[DPEM_FIELD_LOCAL_NAME] = get_post_meta( $post->ID, DPEM_FIELD_LOCAL_NAME, true );
                $metadata[DPEM_FIELD_LOCAL_DESC] = get_post_meta( $post->ID, DPEM_FIELD_LOCAL_DESC, true );
                $metadata[DPEM_FIELD_ORGANIZER]  = get_post_meta( $post->ID, DPEM_FIELD_ORGANIZER, true );
                $metadata[DPEM_FIELD_STARTDATE]  = get_post_meta( $post->ID, DPEM_FIELD_STARTDATE, true );
                $metadata[DPEM_FIELD_ENDDATE]    = get_post_meta( $post->ID, DPEM_FIELD_ENDDATE, true);
                $metadata[DPEM_FIELD_STARTTIME]  = get_post_meta( $post->ID, DPEM_FIELD_STARTTIME, true);
                $metadata[DPEM_FIELD_ENDTIME]    = get_post_meta( $post->ID, DPEM_FIELD_ENDTIME, true);

                $event_block = '';
                $event_block .= 'Where?: ' . $metadata[DPEM_FIELD_LOCAL_NAME] . '<br />';
                $event_block .= 'Organized by: ' . $metadata[DPEM_FIELD_ORGANIZER] . '<br />';
                $event_block .= 'About the place: ' . $metadata[DPEM_FIELD_LOCAL_DESC] . '<br />';
                $event_block .= 'Start Date: ' . $metadata[DPEM_FIELD_STARTDATE] ;

                if ( !empty( $metadata[DPEM_FIELD_STARTTIME] ) ) {
                    $event_block .= ' @ ' . $metadata[DPEM_FIELD_STARTTIME];
                }
                $event_block .= '<br />';
                $event_block .= 'End Date: ' . $metadata[DPEM_FIELD_ENDDATE];
                if ( !empty( $metadata[DPEM_FIELD_ENDTIME] ) ) {
                    $event_block .= ' @ ' . $metadata[DPEM_FIELD_ENDTIME];
                }
                $event_block .= '<br />';

                $content = $old_content . $event_block;
            } else {
                $content = $old_content;
            }
            return $content;
    }
}

new dia_pucp_events_showroom();

//' @ ' . get_post_meta( $post->ID, DPEM . 'starttime', true );
//  'End Date:' . get_post_meta( $post->ID, DPEM . 'enddate', true ) . ' @ ' . get_post_meta( $post->ID, DPEM . 'endtime', true ) . '</td></tr>';

/*
$event_block =
    '<style type="text/css">'.
        '.events-table { color: white; border: 1px solid white; width: 100%; }' .
    '</style>';
*/

//$metakeys = get_post_custom_keys();
//$this->filter_custom_keys($metakeys);

/*
    public function filter_custom_keys($metakeys){
        foreach($metakeys as $key=>$value ){
            if ( strpos($value,DPEM) === false ){
                unset( $metakeys[$key] );
            }
        }
    }
*/
/*
    function events_archive( $template ) {
        var_dump($template);
    }
*/
/*
    public function events_post_breadcrumb( $crumb ){
        global $post;

        $category_id = get_cat_ID( 'Eventos' );

        if ( $post->post_type == 'event' ){
            $crumb = '<a href="' . get_category_link($category_id) . '">'.'Eventos'.'</a> / ' . $post->post_title;
        }
        return $crumb;
    }
*/
/*
    function special_loop() {
        $loop = new WP_Query( array( 'post_type' => array('events','posts'), 'posts_per_page' => 20 ) ); ?>
        <div id="events">
        <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
            <div id="post-<?php the_ID(); ?>">

            </div><!--end #specials -->
        <?php endwhile;?>
        </div>
        <?php
    }
*/

?>
